//
//  CZBaseViewController.swift
//  Swift -- 微博
//
//  Created by sks on 16/6/26.
//  Copyright © 2016年 mohaha. All rights reserved.
//

import UIKit

class CZBaseViewController: UITableViewController {
    
    //判断用户是否登录
    let isLogIn :Bool = CZUserAccountTools.sharedTools.isLogin
    
    override func loadView() {
        if isLogIn {
            
             super.loadView()
            
        }else{
            
       
             setupVisitorView()
          
        }
    }
    

    private func setupVisitorView(){
      
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(CZBaseViewController.btnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(CZBaseViewController.btnClick))
        
        visitorView = CZVistorView()
        visitorView.closure = {[weak self] in
        
        self?.btnClick()
        }
        view = visitorView
        
    }
    
    
    @objc private func btnClick () {
    
        let oauthVC = CZOAuthViewController()
        let nvc = UINavigationController(rootViewController: oauthVC)
        
        presentViewController(nvc, animated: true, completion: nil)
        
        
     
    }
    
    //访客视图的懒加载
    lazy var visitorView :CZVistorView = {
       let view  = CZVistorView()
      return view
    }()
    
    
    

}
